<?php
require_once("class.markup_configs_helper.php");
function compare($key1,$key2)
{
    if($key1["priority"]>$key2["priority"])
    {
        return -1;
    }
    else
    if($key1["priority"]<$key2["priority"])
    {
        return +1;
    }
    else
    {
        return 0;
    }
}
class markup_config{
      var $config_id;
      var $fare_type;
      var $airline_code;
      var $trip_type;
      var $ptc;
      var $cabin_class;
      var $sid;
      var $range;
      var $time_search;
      var $flight_type;
      var $rule_id;
      var $config_mark= array();
      var $dbhan;
      var $applicable_rule;
      
function markup_config($config_id,$ft,$ac,$tt,$ptc,$cab,$sid,$ran,$time,$fli_typ)
{
          $this->config_id=$config_id;
          $this->fare_type=$ft;
          $this->airline_code=$ac;
          $this->trip_type=$tt;
          $this->ptc=$ptc;
          $this->cabin_class=$cab;
          $this->sid=$sid;
          $this->range=$ran;
          $this->time_search=$time;
          $this->flight_type=$fli_typ;
          
}
function assign_markup()
{
         
          $this->config_mark=markup_configs_helper::get_markup_by_config($this->config_id);
          $this->initialize();
          $this->fare_type_filter($this->fare_type);
          $this->airline_filter($this->airline_code);
          $this->trip_type_filter($this->trip_type);
          $this->ptc_filter($this->ptc);
          $this->cabin_type_filter($this->cabin_class);
          $this->sid_filter($this->sid);
          $this->range_filter($this->range);
          $this->search_time_filter($this->time_search);
          $this->flight_type_filter($this->flight_type);
          $this->prioritize();
          
          
      }
      
function prioritize()
{
          usort($this->config_mark,"compare");
          $this->applicable_rule=$this->config_mark[0];
      }
function initialize()
{
          $arr=array();
          foreach($this->config_mark as $ele)
          {
              $ele["priority"]=0;
              $arr[]=$ele;
          }
          $this->config_mark=$arr;
          
      }
function fare_type_filter($ft)
{     $arr=array();
        foreach($this->config_mark as $ele)
        {
               if($ele["fare_type"]==$ft)
               {
                   $ele["priority"]+=15000;
               }
               else if($ele["fare_type"]=="ALL")
               {
                    $ele["priority"]+=14900;
               }
               else
               {
                    $ele["priority"]=0;             
               }
               $arr[]=$ele;
        }  
         $this->config_mark=$arr;
      }
function airline_filter($ac)
{     $arr=array();
       foreach($this->config_mark as $ele)
        {
              if($ele["airline_code"]==$ac)
               {
                   $ele["priority"]+=14000;
               }
               else if($ele["airline_code"]=="ALL")
               {
                   $ele["priority"]+=13900;
               }
               else
               {
                    $ele["priority"]=0;             
               }
               $arr[]=$ele;
        }  
         $this->config_mark=$arr;   
      }
function trip_type_filter($tt)
{      $arr=array();
         foreach($this->config_mark as $ele)
        {
              if($ele["trip_type"]==$tt)
               {
                   $ele["priority"]+=13000;
               }
               else if($ele["trip_type"]=="ALL")
               {
                    $ele["priority"]+=12900;
               }
               else
               {
                    $ele["priority"]=0;             
               }
               $arr[]=$ele;
        }  
         $this->config_mark=$arr;     
      }
function ptc_filter($ptc)
{       $arr=array();
           foreach($this->config_mark as $ele)
        {
              if($ele["ptc"]==$ptc)
               {
                   $ele["priority"]+=12000;
               }
               else if($ele["ptc"]=="ALL")
               {
                    $ele["priority"]+=11900;
               }
               else
               {
                    $ele["priority"]=0;             
               }
               $arr[]=$ele;
        } 
         $this->config_mark=$arr;    
}

function cabin_type_filter($cab)
      {      $arr=array();
           foreach($this->config_mark as $ele)
           {
              if($ele["cabin_class"]==$cab)
               {
                   $ele["priority"]+=11000;
               }
               else if($ele["cabin_class"]=="ALL")
               {
                    $ele["priority"]+=10900;
               }
               else
               {
                    $ele["priority"]=0;             
               }
               $arr[]=$ele;
        }
         $this->config_mark=$arr;
          
      }
      
      function sid_filter($sid)
      {     $arr=array();
        foreach($this->config_mark as $ele)
           {
              if($ele["sid"]==$sid)
               {
                   $ele["priority"]+=10000;
               }
               else if($ele["sid"]=="ALL")
               {
                    $ele["priority"]+=9900;
               }
               else
               {
                   $ele["priority"]=0;             
               }
               $arr[]=$ele;
        } 
         $this->config_mark=$arr; 
      }
      
      function range_filter($ran)
      {     $arr=array();
          foreach($this->config_mark as $ele)
           {
              if($ele["price_range"]==$ran)
               {
                   $ele["priority"]+=9000;
               }
               else if($ele["price_range"]=="ALL")
               {
                    $ele["priority"]+=8900;
               }
               else
               {
                    $ele["priority"]=0;             
               }
               $arr[]=$ele;
        } 
         $this->config_mark=$arr;
          
      }
      function search_time_filter($srt)
      {      $arr=array();
         foreach($this->config_mark as $ele)
           {
              if($ele["time_search"]==$srt)
               {
                   $ele["priority"]+=8000;
               }
               else if($ele["time_search"]=="ALL")
               {
                    $ele["priority"]+=7900;
               }
               else
               {
                   $ele["priority"]=0;             
               }
               $arr[]=$ele;
        }  
         $this->config_mark=$arr;
      }
      
      function flight_type_filter($flt)
      {    $arr=array();
        foreach($this->config_mark as $ele)
           {
              if($ele["flight_type"]==$flt)
               {
                   $ele["priority"]+=7000;
               }
               else if($ele["flight_type"]=="ALL")
               {
                    $ele["priority"]+=6900;
               }
               else
               {
                    $ele["priority"]=0;             
               }
               $arr[]=$ele;
        } 
         $this->config_mark=$arr; 
      }
      
     
  }
?>
